package com.chaoyer.cynet.common.domain;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ErrorInfo {
    private final long code;

    @JSONField(serialize = false)
    private final String name;

    private String msg;

    public ErrorInfo(ErrorInfo errorInfo, String msg) {
        this(errorInfo.getCode(), errorInfo.getName(), msg);
    }

    public ErrorInfo(long code, String name) {
        this.code = code;
        this.name = name;
    }

    public ErrorInfo(long code, String name, String msg) {
        this(code, name);
        this.msg = msg;
    }

    public ErrorInfo setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    @Override
    public String toString() {
        return "Error Code(" + code + ") Name:" + name + " Msg:" + msg;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ErrorInfo)) {
            return false;
        }
        return this.code == ((ErrorInfo) o).getCode();
    }
}
